package com.liu.communitysystemend.module.visitor.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liu.communitysystemend.module.visitor.domain.Visitor;
import com.liu.communitysystemend.module.visitor.service.VisitorService;
import com.liu.communitysystemend.utils.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author liu
 * @create 2023-03-02 14:17
 */
@RestController
@RequestMapping("/api/visitor")
public class VisitorController {
    @Autowired
    private VisitorService visitorService;

    @ApiOperation("更新来访信息")
    @GetMapping("/get/{id}")
    public Result<Visitor> getComplaints(@PathVariable("id")String id){
        return Result.success(visitorService.getVisitorById(id));
    }

    @ApiOperation("更新来访信息")
    @PostMapping("modify")
    public Result<Visitor> save(@RequestBody Visitor visitor) {
        return Result.success(visitorService.update(visitor));
    }

    @ApiOperation("添加来访信息")
    @PostMapping("add")
    public Result<Visitor> add(@RequestBody Visitor visitor){
        return Result.success(visitorService.add(visitor));
    }

    @ApiOperation("查询来访列表(分页)")
    @PostMapping("page")
    public Result<Page<Visitor>> getPage(@RequestBody Visitor visitor) {
        return Result.success(visitorService.getPage(visitor));
    }

    @GetMapping("delete/{id}")
    @ApiOperation("删除来访")
    public Result deleteById(@PathVariable("id") String id) {
        return visitorService.deleteById(id) > 0 ? Result.success() : Result.failed();
    }

    @ApiOperation("来访test")
    @GetMapping("/test")
    public Result test(){
        return Result.success(visitorService.test());
    }

}

